package ui;

import java.math.BigDecimal;

import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.swt.graphics.Image;

import data.Constant;
import data.TimeStock;

public class TableLabelProvider extends LabelProvider implements ITableLabelProvider {
	public Image getColumnImage(Object element, int columnIndex) {
		return null;
	}
	public String getColumnText(Object element, int columnIndex) {
		TimeStock ts = (TimeStock)element;
		if (ts.getCurPrice() == null && columnIndex != 0
				&& columnIndex != 1) {
			return "";
		}
		switch (columnIndex) {
		case 0:
			return ts.getCode();
		case 1:
			return ts.getStockName();
		case 2:
			return ts.getCurPrice().toString();
		case 3:
			return ts.getCurPrice().subtract(ts.getPreDayPrice())
					.toString();
		case 4:
			BigDecimal increPriceRate = ts.getRatePercent();
			if (increPriceRate.compareTo(Constant.ZERO) > 0) {
				return "+" + increPriceRate + "%";
			} else {
				return increPriceRate + "%";
			}
		case 5:
			return ts
					.getAmount().toString();
		case 6:
			return ts.getAmountBat().toString();
		case 7:
			return ts.getTime().toString();
		case 8:
			return ts.getMaxPrice().toString();
		case 9:
			return ts.getMinPrice().toString();
		case 10:
			return ts.getIndustry();
		case 11:
			return ts.getSinaIndustry();
		case 12:
			int info = ts.getInfo();
			if(info==-1){
				return "卖出";
			}else if(info==1){
				return "买入";
			}
			return "未确认";
		case 13:
			return ts.getPriceWive().toString();
		case 14:
			if(ts.getSelectTime()!=null){
				return ts.getSelectTime().toString();
			}else{
				return "";
			}
		case 15:
			if(ts.getSelectPrice()!=null){
				return ts.getSelectPrice().toString();
			}else{
				return "";
			}
		case 16:
			if(ts.getSelectPrice()!=null){
				return ts.getCurPrice().subtract(ts.getSelectPrice()).multiply(Constant.ONEHUNDRED).divide(ts.getPreDayPrice(),2,BigDecimal.ROUND_HALF_UP).toString();
			}else{
				return "";
			}
		case 17:
			if(ts.getAmountInrecTime()!=null){
				return ts.getAmountInrecTime().toString();
			}else{
				return "";
			}
		case 18:
			if(ts.getQtyBat()!=0){
				return String.valueOf(ts.getQtyBat());
			}else{
				return "";
			}
		case 19:
			return String.valueOf(ts.getHighHit());
		case 20:
			return ts.getMark();
		default:
			return "";
		}
	}
}